package com.atguigu.mall.mallproduct.controller;

import java.util.Arrays;
import java.util.Map;

import com.atguigu.common.valid.AddGroup;
import com.atguigu.common.valid.UpdateStatusGroup;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.atguigu.mall.mallproduct.entity.PmsBrandEntity;
import com.atguigu.mall.mallproduct.service.PmsBrandService;
import com.atguigu.common.utils.PageUtils;
import com.atguigu.common.utils.R;

/**
 * 品牌
 *
 * @author Fuc
 * @email leftbear@gmail.com
 * @date 2020-10-21 14:01:49
 */
@RestController
@RequestMapping("mallproduct/pmsbrand")
public class PmsBrandController {
  @Autowired private PmsBrandService pmsBrandService;

  /** 列表 */
  @RequestMapping("/list")
  public R list(@RequestParam Map<String, Object> params) {
    PageUtils page = pmsBrandService.queryPage(params);

    return R.ok().put("page", page);
  }

  /** 信息 */
  @RequestMapping("/info/{brandId}")
  public R info(@PathVariable("brandId") Long brandId) {
    PmsBrandEntity pmsBrand = pmsBrandService.getById(brandId);

    return R.ok().put("pmsBrand", pmsBrand);
  }

  /** 保存 */
  @RequestMapping("/save")
  public R save(@Validated({AddGroup.class}) @RequestBody PmsBrandEntity pmsBrand) {
    pmsBrandService.save(pmsBrand);
    return R.ok();
  }

  /** 修改 */
  @RequestMapping("/update")
  public R update(@RequestBody PmsBrandEntity pmsBrand) {
    pmsBrandService.updateById(pmsBrand);

    return R.ok();
  }

  /** 修改状态 */
  @RequestMapping("/update/status")
  public R updateStatus(@Validated(UpdateStatusGroup.class) @RequestBody PmsBrandEntity pmsBrand) {
    pmsBrandService.updateById(pmsBrand);

    return R.ok();
  }

  /** 删除 */
  @RequestMapping("/delete")
  public R delete(@RequestBody Long[] brandIds) {
    pmsBrandService.removeByIds(Arrays.asList(brandIds));

    return R.ok();
  }
}
